package com.example.mydesignmodule.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tgw
 * @date 2021/1/26
 *过滤器模式
 */
public class FilterRunMain {

    public static void main(String[] args) {
        List<FilterBean> persons = new ArrayList<FilterBean>();

        persons.add(new FilterBean("tgw","31", "长沙"));
        persons.add(new FilterBean("John","20", "杭州"));
        persons.add(new FilterBean("Laura","30", "上海"));
        persons.add(new FilterBean("tgw","20", "杭州"));
        persons.add(new FilterBean("Mike","21", "长沙"));
        persons.add(new FilterBean("Bobby","20", "上海"));

        System.out.println("过滤名称tgw---");
        IFilterBase name = new NameFilter();
        printPersons(name.getFilterList(persons));
        System.out.println("过滤年龄20---");
        IFilterBase age = new AgeFilter();
        printPersons(age.getFilterList(persons));
        System.out.println("过滤地址长沙---");
        IFilterBase address = new AddressFilter();
        printPersons(address.getFilterList(persons));
        System.out.println("过滤地址长沙+名称tgw---");
        printPersons(name.getFilterList(address.getFilterList(persons)));
    }
    public static void printPersons(List<FilterBean> persons){
        for (FilterBean person : persons) {
            System.out.println("Person : [ Name : " + person.getName()
                    +", age : " + person.getAge()
                    +", address  : " + person.getAddress()
                    +" ]");
        }
    }
}
